<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="ctx" value="${pageContext.request.contextPath}"></c:set>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
	h3{
		text-align:center;
	}
	table{
		margin:0 auto;
		width:980px;
		border:1px solid black;
		border-collapse:collapse;
	}
	td{
		border:1px solid black;
	}
	div{
		margin:0 auto;
		text-align:center;
	}
</style>
</head>
<body>
	<h3>用户管理</h3>
	<div>
		<a href="${ctx}/admin/user/adduser.jsp">新增</a>&nbsp;&nbsp;
		<a href="${ctx}/user?type=get&id=" id="editUser">修改</a>&nbsp;&nbsp;
		<a href="#">删除</a>&nbsp;&nbsp;
		<a href="#">重置密码</a>&nbsp;&nbsp;
		<a href="#">退出管理后台</a>&nbsp;&nbsp;
		<a href="${ctx}/index">网站前台</a>&nbsp;&nbsp;
	</div>
	<table>
		<tr>
			<td><input type="checkbox" name="checkAll" id="checkAll"/></td>
			<td>编号</td>
			<td>账号</td>
			<td>角色</td>
			<td>操作</td>
		</tr>
		<c:forEach items="${userList}" var="obj">
			<tr>
				<td><input type="checkbox" name="checkOne" id="checkOne"  value="${obj.id}"/></td>
				<td>${obj.id}</td>
				<td>${obj.username}</td>
				<td>${obj.roleName}</td>
				<td>
					<a href="${ctx}/user?type=get&id=${obj.id}">编辑</a>
					<a href="${ctx}/user?type=del&id=${obj.id}" onclick="return confirm('确定要删除？');">删除</a>
				</td>
			</tr>
		</c:forEach>		
	</table>
<script>
	var checkAll=document.getElementById("checkAll");
	var checkOnes=document.getElementsByName("checkOne");
	var editUser=document.getElementById("editUser");
	checkAll.onclick=function(){
		if(checkAll.checked){
			for(var i=0;i<checkOnes.length;i++){
				checkOnes[i].checked=true;
			}
		}else{
			for(var i=0;i<checkOnes.length;i++){
				checkOnes[i].checked=false;
			}
		}		
	}
	for(var i=0;i<checkOnes.length;i++){
		checkOnes[i].onclick=function(){
			var flag=true;
			for(var i=0;i<checkOnes.length;i++){
				if(checkOnes[i].checked==false){
					flag=false;
					break;
				}
			}
			checkAll.checked=flag;
		}
	}
	editUser.onclick=function(){
		alert("jinru")
		var count=0;
		var id=0;
		for(var i=0;i<checkOnes.length;i++){
			if(checkOnes[i].checked==true){
				count=count+1;
				id=checkOnes[i].value;
			}
		}
		if(count!=1){
			alert("您只能选择1条记录进行编辑！");
			return false;
		}else{
			alert("${ctx}/user?type=get&id="+id);
			editUser.href="${ctx}/user?type=get&id="+id;
			return true;
		}
		
	}
	
	
</script>
</body>
</html>
